package com.finesys.backend.api.aop;

import com.finesys.backend.api.anno.LoggerPolicy;
import org.apache.dubbo.config.annotation.DubboReference;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.lang.reflect.Method;


/**
 * @author lehoon
 * <p>Description: </p>
 * 2020年10月12日
 */
@Aspect
@Component
public class WebAspect {
	@Pointcut("execution(public * com.finesys.backend.api.controller..*.*(..))")
	public void webAccess(){}
	
	@Before("webAccess()")
	public void doBefore(JoinPoint joinPoint) throws Throwable{
    	String methodName = joinPoint.getSignature().getName();
		if(null != methodName && !"".equals(methodName)){
			if (!(methodName.startsWith("set") || methodName.startsWith("get"))) {
				Class<? extends Object> pointClass = joinPoint.getTarget().getClass();
				Class<? extends Object>[] parameterTypes = ((MethodSignature)joinPoint.getSignature()).getMethod().getParameterTypes();
				Method method = pointClass.getMethod(methodName,parameterTypes);
				if(null != method){
					boolean hasAnno = method.isAnnotationPresent(LoggerPolicy.class);
					if(hasAnno){
						LoggerPolicy cicController = method.getAnnotation(LoggerPolicy.class);
						String des = cicController.description();
						//记录日志
					}
				}
			}
		}
	}
	
	@AfterReturning(returning = "re", pointcut = "webAccess()")
	public void doAfterReturning(Object re){
	}

}
